package com.market.cash.utils.decoration;

import android.graphics.Rect;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;


/**
 * CashRoot
 * @Author wwdeng
 * @CreateTime: 2024/10/17 11:59
 * @Annotation：LinearLayoutManager 设置item的间隔
 */
public class LinearSpacingItemDecoration extends RecyclerView.ItemDecoration {
    private int leftSpace;
    private int rightSpace;
    private int topSpace;
    private int bottomSpace;

    public LinearSpacingItemDecoration(int leftSpace, int rightSpace, int topSpace, int bottomSpace) {
        this.leftSpace = leftSpace;
        this.rightSpace = rightSpace;
        this.topSpace = topSpace;
        this.bottomSpace = bottomSpace;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view,RecyclerView parent, RecyclerView.State state) {
        outRect.left = this.leftSpace;
        outRect.right = this.rightSpace;
        outRect.bottom = this.bottomSpace;

        // Add top margin only for the first item to avoid double space between items
        if (parent.getChildPosition(view) == 0)
            outRect.top = this.topSpace;

    }
}
